package com.mlnx.ecg.ui.panels;

import com.mlnx.ecg.ui.config.ECGConfig;
import com.mlnx.ecg.ui.model.Channel;
import com.mlnx.ecg.ui.model.Point;
import com.mlnx.ecg.ui.model.WavePos;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by amanda.shan on 2017/1/13.
 */

public enum EcgShowType {
    _1x12, _2x6, _4x3, _1x1, _1x7;

    public static WavePos getWavePos(EcgShowType ecgShowType, int leadFalg,
                                     int w, int h) {

        switch (ecgShowType) {
            case _1x12:
                return get_1x12_Point(leadFalg, w, h);
            case _2x6:
                return get_2x6_Point(leadFalg, w, h);
            case _4x3:
                return get_4x3_Point(leadFalg, w, h);
            case _1x1:
                return get_1x12_Point(leadFalg, w, h);
            case _1x7:
                return get_1x12_Point(leadFalg, w, h);
        }
        return null;
    }

    public static List<WavePos> getWavePos(Channel channel, int w, int h) {

        List<Integer> list = channel.getSelectChannelFlag();

        List<WavePos> wavePoss = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            int wLeadView = w;
            int hLeadView = h / channel.getSelectSize();

            Point lTop = new Point(0, hLeadView * i); // 左上
            Point lBot = new Point(0, hLeadView * (i + 1)); // 左下
            Point rTop = new Point(wLeadView, hLeadView * i); // 右上
            Point rBot = new Point(wLeadView, hLeadView * (i + 1)); // 右下

            WavePos wavePos = new WavePos();
            wavePos.setlBot(lBot);
            wavePos.setlTop(lTop);
            wavePos.setrBot(rBot);
            wavePos.setrTop(rTop);

            wavePoss.add(wavePos);
        }
        return wavePoss;
    }

    public static WavePos get_1x12_Point(int leadFlag, int w, int h) {
        int wLeadView = w;
        int hLeadView = h / ECGConfig.ECGLEADNAMES.size();

        Point lTop = new Point(0, hLeadView * leadFlag); // 左上
        Point lBot = new Point(0, hLeadView * (leadFlag + 1)); // 左下
        Point rTop = new Point(wLeadView, hLeadView * leadFlag); // 右上
        Point rBot = new Point(wLeadView, hLeadView * (leadFlag + 1)); // 右下

        WavePos wavePos = new WavePos();
        wavePos.setlBot(lBot);
        wavePos.setlTop(lTop);
        wavePos.setrBot(rBot);
        wavePos.setrTop(rTop);

        return wavePos;
    }

    public static WavePos get_2x6_Point(int leadFlag, int w, int h) {
        int startX;

        if (leadFlag / 6 == 0)
            startX = 0;
        else
            startX = w / 2;

        int hLeadView = h / 6;

        Point lTop = new Point(startX, hLeadView * (leadFlag % 6)); // 左上
        Point lBot = new Point(startX, hLeadView * (leadFlag % 6 + 1)); // 左下
        Point rTop = new Point(startX + w / 2, hLeadView * (leadFlag % 6)); // 右上
        Point rBot = new Point(startX + w / 2, hLeadView * (leadFlag % 6 + 1)); // 右下

        WavePos wavePos = new WavePos();
        wavePos.setlBot(lBot);
        wavePos.setlTop(lTop);
        wavePos.setrBot(rBot);
        wavePos.setrTop(rTop);

        return wavePos;
    }

    public static WavePos get_4x3_Point(int leadFalg, int w, int h) {
        int startX;
        Point lTop = null;
        Point lBot = null;
        Point rTop = null;
        Point rBot = null;

        startX = w / 4 * (leadFalg / 3);
        int hLeadView = h / 4;

        if (leadFalg != -1) {
            lTop = new Point(startX, hLeadView * (leadFalg % 3)); // 左上
            lBot = new Point(startX, hLeadView * (leadFalg % 3 + 1)); // 左下
            rTop = new Point(startX + w / 4, hLeadView * (leadFalg % 3)); // 右上
            rBot = new Point(startX + w / 4, hLeadView * (leadFalg % 3 + 1)); // 右下
        } else {
            lTop = new Point(0, hLeadView * 3); // 左上
            lBot = new Point(0, hLeadView * 4); // 左下
            rTop = new Point(w, hLeadView * 3); // 右上
            rBot = new Point(w, hLeadView * 4); // 右下
        }

        WavePos wavePos = new WavePos();
        wavePos.setlBot(lBot);
        wavePos.setlTop(lTop);
        wavePos.setrBot(rBot);
        wavePos.setrTop(rTop);

        return wavePos;
    }

}
